public class VolatileSafe {

    volatile boolean close;

     public void close(){

        close=true;
    }

    public void doWork(){
        while (!close){
            System.out.println("safe....");
        }
        System.out.println(i2);
    }
int i2;
    public static void main(String[] args) throws InterruptedException {
         int i;
        System.out.println(i);

        VolatileSafe vs=new VolatileSafe();
        Thread t1;
        t1 = new Thread(vs::close);
        Thread t2;
        t2 = new Thread(vs::doWork);
        t2.start();
       // t1.start();
        t2.join();
    }
}
